package com.cf.service.impl;

import com.cf.dao.IdTypeDao;
import com.cf.entity.IdType;
import com.cf.service.IdTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class IdTypeServiceImpl implements IdTypeService {
    @Autowired
    private IdTypeDao idTypeDao;
    @Override
    public PageInfo<IdType> selectAllIdType(int pagenum, int pagesize, Map map) {
        PageHelper.startPage(pagenum,pagesize);
        List<IdType> idTypes = idTypeDao.selectAllIdType(map);
        PageInfo<IdType> idTypepageInfo = new PageInfo<>(idTypes);
        return idTypepageInfo;
    }

    @Override
    public int updateIdType(IdType idType) {
        return idTypeDao.updateIdType(idType);
    }

    @Override
    public int addIdType(IdType idType) {
        return idTypeDao.addIdType(idType);
    }

    @Override
    public int delIdType(long id) {
        return idTypeDao.delIdType(id);
    }

    @Override
    public IdType selectById(long id) {
        return idTypeDao.selectById(id);
    }

    @Override
    public PageInfo<IdType> selectAllIdTypeAndZj(int pagenum, int pagesize) {
        String str = "";
        PageHelper.startPage(pagenum,pagesize);
        List<IdType> idTypes = idTypeDao.selectAllIdTypeAndZj();

        for (IdType idType : idTypes) {
            str = "";
            for (int i = 0; i < idType.getChildren().size(); i++) {
                str += idType.getChildren().get(i).getAccountid() + ",";
                idType.setAids(str);
            }
        }
        PageInfo<IdType> idTypepageInfo = new PageInfo<>(idTypes);
        return idTypepageInfo;
    }
}
